package com.stud.system.domain;

import com.baomidou.mybatisplus.annotation.SqlCondition;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.stud.common.annotation.Excel;
import com.stud.common.core.domain.BaseEntity;
import com.stud.common.exception.vaidate.StudValidationException;
import com.stud.common.utils.StringUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;

import javax.validation.Valid;
import java.util.Objects;

/**
 * 流程定义任务对象 t_workflow_definition_task
 *
 * @author Stud
 * @date 2023-03-06
 */
@Schema(description = "流程定义任务")
@Data
@TableName("t_workflow_definition_task")
public class WorkflowDefinitionTask extends BaseEntity {

    @Excel(name = "流程定义编码")
    @Schema(description = "流程编码")
    @NotBlank(message = "流程定义编码不能为空")
    private String definitionCode;

    @TableField(condition = SqlCondition.LIKE)
    @Excel(name = "流程定义名称")
    @NotBlank(message = "流程定义名称不能为空")
    @Schema(description = "流程名称")
    private String definitionName;

    @Excel(name = "任务编码")
    @Schema(description = "任务编码")
    @NotBlank(message = "任务编码不能为空")
    private String taskCode;

    @TableField(condition = SqlCondition.LIKE)
    @Excel(name = "任务名称")
    @Schema(description = "任务名称")
    @NotBlank(message = "任务名称不能为空")
    private String taskName;

    @Excel(name = "任务类型")
    @Schema(description = "任务类型(0:启动任务-通常不需要审核;1:普通任务;2:主任务)")
    @NotBlank(message = "任务类型不能为空")
    private String taskType;

    @Excel(name = "任务表单路径")
    @Schema(description = "任务表单路径")
    private String taskFormPath;

    @TableField(condition = SqlCondition.LIKE)
    @Excel(name = "任务表单名称")
    @Schema(description = "任务表单名称")
    private String taskFormName;

    @Excel(name = "是否需要上传附件(0:不要;1:显示;2:必须)")
    @Schema(description = "是否需要上传附件(0:不要;1:显示;2:必须)")
    private String fileFlag;

    @Excel(name = "审批角色")
    @Schema(description = "审批角色")
    private String roleCode;

    @Excel(name = "表单默认值")
    @Schema(description = "表单默认值")
    private String formDefault;

    @Excel(name = "顺序")
    @Schema(description = "顺序")
    private Integer sortNum;

    @Excel(name = "开关")
    @Schema(description = "开关")
    private String flag;

    @Valid
    public boolean validate() {
        if (!Objects.equals(taskType, "0") && StringUtils.isBlank(taskType)) {
            throw new StudValidationException("审批角色不能为空");
        }

        return true;
    }
}
